package observer.jdk;

import lombok.Getter;

import java.util.Observable;

/**
 * 温度数据
 */
@Getter
public class WeatherData extends Observable {
    private final float temperature;
    private final float pressure;
    private final float humidity;
    private boolean useFahrenheit = false;

    public WeatherData(float temperature,
                       float pressure,
                       float humidity) {
        this.temperature = temperature;
        this.pressure = pressure;
        this.humidity = humidity;
    }

    public void setFahrenheit() {
        useFahrenheit = true;
    }

    /**
     * 变更温度
     */
    public void updateTemperature() {
        // 温度变化了，变成change变量
        super.setChanged();
        // 通知所有观察者
        notifyObservers(useFahrenheit);
    }
}
